package com.lineage.server.serverpackets;

import com.lineage.server.model.Instance.L1PcInstance;

public class S_GmMessage extends ServerBasePacket {
  private static final String AM = "\\aG[%s] \\aD%s: %s";
  
  private static final String[] TYPES = new String[] { "王族", "骑士", "妖精", "法师", "黑暗妖精", "龙骑士", "幻术师", "管理员GM" };
  
  private static final String LOGIN = "\\aE[%s][%s](%s) 登录。";
  
  private static final String SYS = "\\aD[系统] %s%s";
  
  public S_GmMessage(L1PcInstance pc, L1PcInstance target, int type, String text) {
    String t = null;
    switch (type) {
      case 0:
        t = "一般";
        break;
      case 1:
        t = "私密";
        break;
      case 2:
        t = "大喊";
        break;
      case 3:
        t = "全体";
        return;
      case 4:
        t = "血盟";
        break;
      case 11:
      case 14:
        t = "队伍";
        break;
      case 12:
        t = "交易";
        return;
      case 13:
        t = "联盟";
        break;
      default:
        t = "未知";
        return;
    } 
    String to = (target == null) ? pc.getName() : (String.valueOf(String.valueOf(pc.getName())) + "->" + target.getName());
    writeC(243);
    writeC(9);
    writeS(String.format("\\aG[%s] \\aD%s: %s", new Object[] { t, to, text }));
  }
  
  public S_GmMessage(L1PcInstance pc) {
    String type = (pc.isGm() || pc.isMonitor()) ? TYPES[7] : TYPES[pc.getType()];
    writeC(243);
    writeC(9);
    writeS(String.format("\\aE[%s][%s](%s) 登录。", new Object[] { pc.getName(), type, pc.getNetConnection().getIp() }));
  }
  
  public S_GmMessage(String text, String CLR) {
    writeC(243);
    writeC(9);
    writeS(String.format("\\aD[系统] %s%s", new Object[] { CLR, text }));
  }
  
  public final byte[] getContent() {
    return getBytes();
  }
}
